package com.abc.pro186;

import android.app.Application;
import android.content.Context;
import android.os.Build;
import android.os.Handler;
import android.os.Message;
import android.widget.Toast;

public class BaseApplication extends Application {
	
	private static Context sContext;
    private static Toast mAppToast;
    private final static int MSG_SHOW_APPLICATION_TOAST = 1000;

	@Override
	public void onCreate() {
		super.onCreate();
		sContext = this.getApplicationContext();
		
		if (Build.VERSION.SDK_INT < 8) {
            System.setProperty("http.keepAlive", "false");
        }
	}
	
	public static Handler getBaseHandler() {
		return mHandler;
	}
	
	private static Handler mHandler = new Handler() {
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case MSG_SHOW_APPLICATION_TOAST:
				if (mAppToast == null) {
		            mAppToast = Toast.makeText(sContext, String.valueOf(msg.obj), /*LENGTH_SHORT*/0);
		            mAppToast.show();
		        } else {
		            mAppToast.setText(String.valueOf(msg.obj));
		            // mAppToast.cancel();
		            mAppToast.show();
		        }
				break;

			default:
				break;
			}
		};
	};
	
	/**
     * Convenient for showing Toast message throughout application.
     * @param msg message want to show.
     */
    public static void makeToastMsg(String msg) {
        Message msgs = mHandler.obtainMessage(MSG_SHOW_APPLICATION_TOAST, msg);
        mHandler.sendMessage(msgs);
    }
	
}
